reactor: a write must not be truncated, and a finished request must not point at its handle - #263
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ust not point at its handle
EdmondDantes
force-pushed
the
writev-slot-overflow
branch
from
August 21, 2026 06:40
b130357 to
e821878
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Defects in the write path, found while reviewing the awaited vectored write (#262).
A write longer than the platform field was truncated and reported as complete
uv_buf_init()takes anunsigned intand narrows anything longer without a word, whileuv_buf_titself carries asize_ton POSIX and aULONGon Windows. Every write sitewent through it and clamped —
libuv_io_writeatINT_MAX,libuv_io_writevatUINT_MAXper slot,libuv_udp_sendtoby a cast that wraps — whilereq->max_sizekeptthe caller's full length, and the completions report
max_sizeastransferred. Anawaiter comparing the two was told a truncated write had finished.
async_uv_buf_set()fills the fields instead, so nothing is narrowed silently; a lengththe platform field cannot hold is refused before submit, on Windows alone.
Separately,
uv_write()refuses any batch summing aboveUV__IO_MAX_BYTESon everyplatform, so a larger single write is clamped to that limit and reports the clamped
size: the caller's loop continues on a short write. A fire-and-forget caller gets a
refusal instead, because
free_cbcarries no length and a clamp there would drop the tailin silence.
A finished request kept pointing at a handle that may be gone
The awaiter reads the status after its resume and disposes the request there, and
libuv_io_req_disposereadsreq->io. Between the completion and the resume the handlecan be closed and freed —
io_close_cbruns in the same loop turn.The completion now clears
req->iowhen it hands the request to its awaiter, and aclosing handle clears the same pointer in the requests it detaches. Both dispose paths
already guard on
req->io != NULL, and the completions reach the handle throughuv_handle_t::data. A reference on the handle was tried first and dropped: it leaks onthe one exit that frees the request without going through dispose, and a shipping caller
reaches that exit by setting
free_cbafter submit.Also here
writev_nbufsisuint16_t, and a wrappedcount made the completion release nothing — one leaked reference per buffer.
uv_udp_sendsubmit no longer leavessend_req.dataset, which madeudp_req_disposewait forever for a callback that cannot run.libuv_writev_release()replaces three copies of the pre-submit release.Evidence
ext/async/tests: 1104 passed, 0 failed (188 skipped).